package sys.util;

import sys.model.User;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by shugen on 2017/3/6.
 */
public class UserUtil {

    public static User getUser(HttpServletRequest request) {

        HttpSession session = request.getSession();
        Object ss= session.getAttribute("user");
        User user=new User();
        if(ss!=null&&ss.getClass()==User.class)
            user=(User)ss;
        if(user==null||user.getId()==null){
            System.out.println("session中没有用户信息--请重新登入!");
            return null;
        }
        else
            return  user;
    }

    public static void updateUser(HttpServletRequest request,User user) {
        HttpSession session = request.getSession();
        session.setAttribute("user",user);
    }

}
